﻿CREATE TRIGGER [tr_Interviews] 
   ON  [dbo].[t_Interviews] 
   AFTER INSERT,UPDATE
AS 
IF @@ROWCOUNT = 0 RETURN
SET NOCOUNT ON;

IF UPDATE(Weight) AND EXISTS(SELECT * FROM inserted WHERE ISNULL(DoneBy,'') = '')BEGIN
	ROLLBACK TRAN
	RAISERROR('Must select [DoneBy].',16,1)
	RETURN
END

IF UPDATE(Weight)
	UPDATE t_Interviews	SET Date = GETDATE(),
													UserName = dbo.UserName()
	WHERE ID IN (SELECT ID FROM inserted i)

DELETE FROM t_Interviews WHERE ID IN (SELECT ID FROM inserted WHERE Note = 'DELETE')

